package com.ruoyi.miniapp.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.miniapp.api.domain.MiniappOperLog;
import com.ruoyi.miniapp.service.IMiniappOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 操作日志记录Controller
 *
 * @author ruoyi
 * @date 2023-09-16
 */
@RestController
@RequestMapping("/log")
public class MiniappOperLogController extends BaseController
{
    @Autowired
    private IMiniappOperLogService miniappOperLogService;

    /**
     * 查询操作日志记录列表
     */
    @RequiresPermissions("miniapp:log:list")
    @GetMapping("/list")
    public TableDataInfo list(MiniappOperLog miniappOperLog)
    {
        startPage();
        List<MiniappOperLog> list = miniappOperLogService.selectMiniappOperLogList(miniappOperLog);
        return getDataTable(list);
    }

    /**
     * 导出操作日志记录列表
     */
    @RequiresPermissions("miniapp:log:export")
    @Log(title = "操作日志记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MiniappOperLog miniappOperLog)
    {
        List<MiniappOperLog> list = miniappOperLogService.selectMiniappOperLogList(miniappOperLog);
        ExcelUtil<MiniappOperLog> util = new ExcelUtil<MiniappOperLog>(MiniappOperLog.class);
        util.exportExcel(response, list, "操作日志记录数据");
    }

    /**
     * 获取操作日志记录详细信息
     */
    @RequiresPermissions("miniapp:log:query")
    @GetMapping(value = "/{operId}")
    public AjaxResult getInfo(@PathVariable("operId") Long operId)
    {
        return success(miniappOperLogService.selectMiniappOperLogByOperId(operId));
    }

    /**
     * 新增操作日志记录
     */
    @InnerAuth
    @PostMapping
    public AjaxResult add(@RequestBody MiniappOperLog miniappOperLog)
    {
        return toAjax(miniappOperLogService.insertMiniappOperLog(miniappOperLog));
    }

    /**
     * 修改操作日志记录
     */
    @RequiresPermissions("miniapp:log:edit")
    @Log(title = "操作日志记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MiniappOperLog miniappOperLog)
    {
        return toAjax(miniappOperLogService.updateMiniappOperLog(miniappOperLog));
    }

    /**
     * 删除操作日志记录
     */
    @RequiresPermissions("miniapp:log:remove")
    @Log(title = "操作日志记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{operIds}")
    public AjaxResult remove(@PathVariable Long[] operIds)
    {
        return toAjax(miniappOperLogService.deleteMiniappOperLogByOperIds(operIds));
    }
}
